#ifndef MTTCPCLIENT_H
#define MTTCPCLIENT_H

#include <QObject>
#include <QTcpSocket>
#include <QThread>
#include <QTimer>

/// 演示如何使用 moveToThread
class MTTcpClient : public QObject
{
    Q_OBJECT
public:
    explicit MTTcpClient(QObject *parent = nullptr);
    ~MTTcpClient();

    bool connectToHost(const QString &ip, qint64 port);
    void disconnect();
    bool isConnected();
signals:
    bool sig_connnectToHost(const QString &ip, qint64 port);

private slots:
    bool on_connectToHost(const QString &ip, qint64 port);
    //客户端槽函数
    void onClientConnected();
    void onClientDisconnected();
    void onClientDataReady();
    void onClientBytesWritten(qint64 bytes);
    void onClientError(QAbstractSocket::SocketError socketError);

private:
    /// 连接到tracker的socket
    QScopedPointer<QTcpSocket> m_client;
    QThread m_clientThread;

};

#endif // MTTCPCLIENT_H
